//axios
axios({
  url: 'http://cba.itlike.com/public/index.php?s=/api//page/detail',
  params: {
    pageId:'0'
  }
}).then(res => {
  console.log(res.data.data.pageData)
  const slides = document.querySelector('.swiper-wrapper')
  slides.innerHTML = res.data.data.pageData.items[1].data.map(ele=> `
  <div class="swiper-slide">
      <img data-id="${ele.link.form[0].value}" src=${ele.imgUrl} alt="" />
    </div>
  `).join('')

  document.querySelector('.nav ul').innerHTML = res.data.data.pageData.items[3].data.map(ele => `
        <li class="gooditem">
          <img class="gooditem" src=${ele.imgUrl} alt="" />
          <div class="tex gooditem">${ele.text}</div>
        </li>
  `).join('')

  document.querySelector('.goods ul').innerHTML = res.data.data.pageData.items[6].data.map(ele => `
        <li data-id="${ele.goods_id}" class="gooditem">
          <div data-id="${ele.goods_id}" class="left gooditem"><img class="gooditem" data-id="${ele.goods_id}" src=${ele.goods_image} alt="" /></div>
          <div data-id="${ele.goods_id}" class="right gooditem">
            <h5 class="ellipsis-2 gooditem" data-id="${ele.goods_id}">
             ${ele.goods_name}
            </h5>
            <span data-id="${ele.goods_id}" class="gooditem">已售${ele.goods_sales}件</span>
            <span data-id="${ele.goods_id}" class="price gooditem">¥${ele.goods_price_max} <i class="gooditem">${ele.line_price_max !=='0.00' ? '¥' + ele.line_price_max :ele.selling_point}</i></span>
          </div>
        </li>
  
  `).join('')
})







//点击跳转搜索
document.querySelector('.serceh').addEventListener('click', function () {
  location.href = 'search.html'
})

  // 点击猜你喜欢跳转商品详情
document.querySelector('.goods ul').addEventListener('click', function (e) {
  console.log(e.target.dataset.id)
  localStorage.setItem('goodsInformation', e.target.dataset.id)
  location.href = './commodity.html'
})

// 点击轮播图跳转商品详情
document.querySelector('.swiper-wrapper').addEventListener('click',e =>{
  // console.log(e.target.dataset.id)
  localStorage.setItem('goodsInformation',e.target.dataset.id)
  location.href = './commodity.html'
})
  
